<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Master React C02.3 Component 生命周期</title>
    <script src="https://cdn.bootcss.com/react/16.2.0/umd/react.production.min.js"></script>
    <script src="https://cdn.bootcss.com/react-dom/16.2.0/umd/react-dom.production.min.js"></script>
    <script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>

    <link href="https://cdn.bootcss.com/highlight.js/9.12.0/styles/vs2015.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>

    <script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div id="root"></div>
<p>代码</p>
<pre><code class="js">    ReactDOM.render(
        < h1 >欢迎使用React!< /h1>,
        document.getElementById('example')
    );
</code></pre>
<script type="text/babel">
    class HelloMessage extends React.Component{
        componentWillMount() {
            console.log('componentWillMount');
        }
        componentDidMount() {
            console.log('componentDidMount');
        }
        componentWillUnmount() {
            console.log('componentWillUnmount');
        }
        render() {
            console.log('render');
            return <h2>{this.props.message}</h2>;
        }
    };

    class HelloReact extends React.Component{
        constructor(){
            super();
            this.state = {
                firstName: '',
                lastName:''
            }
        }
        reload() {
            ReactDOM.unmountComponentAtNode(
                document.getElementById('root'));
            ReactDOM.render(
                <HelloReact/>,
                document.getElementById('root'));
        }
        update(){

        }

        render() {
            return (
                <div>
                    <HelloMessage
                        message={'Hello '
                        + this.state.firstName + ' '
                        + this.state.lastName}>
                    </HelloMessage>
                    <button onClick={this.reload.bind(this)}>Reload</button>
                </div>
            );
        }
    }
    ReactDOM.render(
        <HelloReact/>
        , document.getElementById('root')
    );
</script>

</body>
</html>